#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1.2e6 + 5;

int n, m;
int a[N], b[N];
int cnt[N];
int ans[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) b[a[i]]++;
  int mx = *max_element(a + 1, a + n + 1);
  rep(i, 1, mx) {
    for (int j = i; j <= mx; j += i) cnt[i] += b[j];
  }
  rep(i, 1, mx) {
    if (cnt[i] < m) continue;
    for (int j = i; j <= mx; j += i) ans[j] = max(ans[j], i);
  }
  rep(i, 1, n) cout << ans[a[i]] << endl;
  return 0;
}